<%--
  Created by IntelliJ IDEA.
  User: David
  Date: 2017/7/30 030
  Time: 17:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>JavaWeb登陆示例</title>
        <%--<meta http-equiv="refresh" content="3;url=login.html">--%>
        <script src="//lib.sinaapp.com/js/jquery/3.1.0/jquery-3.1.0.min.js"></script>
    </head>
    <body>
    <%--<a href="login.html">Login</a>--%>
    <%
        Object emailSession = session.getAttribute("login_user_email");
        String email = null;
        if (emailSession == null){

            out.print("<a href=\"login.html\">Login</a>");
            // 重定向到新地址
            String site = "/login.html";
            response.setStatus(response.SC_MOVED_TEMPORARILY);
            response.setHeader("Location", site);
            return;
        }

        email = emailSession.toString();
        if (email.isEmpty()) {
            out.print("<a href=\"login.html\">Login</a>");
            // 重定向到新地址
            String site = "/login.html";
            response.setStatus(response.SC_MOVED_TEMPORARILY);
            response.setHeader("Location", site);
            return;
        }

        
    %>

    <div>
        邮箱：<span id="emailLabel"><% out.print(email); %></span>
    </div>
    <div id="activeMsg" style="display: none;">
        邮件暂未激活
    </div>

    <div>
        用户名：<span id="usernameLabel"></span>
    </div>
    <div>
        性别：<span id="sexLabel"></span>
    </div>
    <div>
        地区：<span id="areaLabel"></span>
    </div>

    <a href="logout">登出</a>

    <script>
        $(document).ready(function () {
            $.get("/userinfo", function(resp){
                var result = JSON.parse(resp);
                var data = result.data;
                console.log(data);
                $("#usernameLabel").html(data.username);
                $("#sexLabel").html(data.sex);
                $("#areaLabel").html(data.area);
                if(result.email_active == "0"){
                    $("#activeMsg").css("display", "block");
                }
            })
        });

    </script>

    </body>
</html>
